package com.pmcc.platform.user.web;

import com.pmcc.platform.user.repository.UserInfoRepository;
import com.pmcc.platform.user.service.UserService;
import com.pmcc.utils.AntPage;
import com.pmcc.utils.ApiResultBean;
import com.pmcc.utils.StringUtil;
import com.pmcc.utils.wechat.HttpClientUtil;
import lombok.extern.slf4j.Slf4j;
import net.sf.json.JSONObject;
import org.apache.commons.collections.map.HashedMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.io.UnsupportedEncodingException;
import java.util.Map;


@RestController()
@RequestMapping("api/v1/user")
@Slf4j
public class UserInfoController {

    @Autowired
    UserService userService;

    @Autowired
    UserInfoRepository userInfoRepository;


    /**
     * 查看所有用户
     * @param antPage
     * @return
     */
    @RequestMapping(value = "/queryAllUser")
    @ResponseBody
   public ApiResultBean queryAllUser(AntPage antPage,String nickname,String provinces ,String city){
        return userService.queryAllUser(antPage,nickname,provinces,city);
   }

    /**
     * 查看用户领取记录
     * @param userId
     * @param antPage
     * @return
     */
    @RequestMapping(value = "/userGetLog")
    @ResponseBody
   public ApiResultBean userGetLog(String userId,AntPage antPage){
       return userService.userGetLog(userId,antPage);
   }




















/*    @RequestMapping(value = "/test", method = RequestMethod.GET)
    @ResponseBody
    public ApiResultBean notif(String mid, String phone, String order_id, String order_no, String status, String use_time, String reserved) {

        ApiResultBean apiResultBean = new ApiResultBean();

        Map<String, Object> map = new HashedMap();
        map.put("mid", mid);
        map.put("phone", phone);
        map.put("order_id", order_id);
        map.put("order_no", order_no);
        map.put("status", status);
        map.put("use_time", use_time);
        if (StringUtil.isNotEmpty(reserved)) {
            map.put("reserved", reserved);

        }

        String aa = null;
        JSONObject jsonMap = JSONObject.fromObject(map);
        try {
            //测试

            aa = HttpClientUtil.doPostJson("http://test.jf180.cn/octopus/vinda/notify", jsonMap.toString());
            //生产
            //String aa=HttpUtils.sendPost("http://open.jf180.cn/octopus/vinda/notify",param);
        } catch (Exception e) {
            e.printStackTrace();
        }

        JSONObject jsonObject = JSONObject.fromObject(aa);
        apiResultBean.setCode(jsonObject.get("code").toString());
        apiResultBean.setMsg(jsonObject.get("message").toString());
        return apiResultBean;
    }


    @RequestMapping(value = "/test1", method = RequestMethod.GET)
    @ResponseBody
    public ApiResultBean activity(String merchantId, String activityNo, int productValue, String title, String usageRules, int stockCount, int activityStatus, int type, String beginTime,
                                  String endTime, String reserved) {
        ApiResultBean apiResultBean = new ApiResultBean();

        Map<String, Object> map = new HashedMap();
        map.put("merchantId", merchantId);
        map.put("activityNo", activityNo);
        map.put("productValue", productValue);
        map.put("title", title);
        map.put("usageRules", usageRules);
        map.put("stockCount", stockCount);
        map.put("activityStatus", activityStatus);
        map.put("type", type);
        map.put("beginTime", beginTime);
        map.put("endTime", endTime);
        if (StringUtil.isNotEmpty(reserved)) {
            map.put("reserved", reserved);

        }
        JSONObject jsonMap = JSONObject.fromObject(map);

        String aa = null;
        try {
            //测试
            aa = HttpClientUtil.doPostJson("http://test.jf180.cn/octopus/vinda/coupon/activity", jsonMap.toString());

            //生产
            //String aa=HttpUtils.sendPost("http://open.jf180.cn/octopus/vinda/coupon/activity ,param);
        } catch (Exception e) {
            e.printStackTrace();
        }


        JSONObject jsonObject = JSONObject.fromObject(aa);
        apiResultBean.setCode(jsonObject.get("code").toString());
        apiResultBean.setMsg(jsonObject.get("message").toString());
        return apiResultBean;
    }*/


}
